package se.webbzon.oschi01.imageset;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import javax.imageio.ImageIO;

import se.webbzon.oschi01.resourceset.ResourceSetLoader;
import se.webbzon.oschi01.resourceset.ResourceSetLoaderException;

public class ImageSetLoader extends ResourceSetLoader<Image> {
	
	/*============================================================
	Public Methods
	============================================================*/
	
	/** Adds a buffered image to the end of the image set. **/
	public boolean addBufferedImage(BufferedImage bufferedImage) {
		return addResource(bufferedImage);
	}
	
	/** Adds an image from a file to the end of the image set. **/
	public boolean addImageFromFile(File file) throws IOException {
		return addResource(ImageIO.read(file));
	}

	@Override public boolean supportsAddFromURL() {
		return true;
	}

	@Override public boolean addFromURL(URL resourceURL)
			throws ResourceSetLoaderException {
		try {
			return addFromInputStream(resourceURL.openStream());
		} catch (IOException e) {
			throw new ResourceSetLoaderException(e);
		}
	}

	@Override public boolean supportsAddFromInputStream() {
		return true;
	}

	@Override public boolean addFromInputStream(InputStream inputStream)
			throws ResourceSetLoaderException {
		try {
			return addResource(ImageIO.read(inputStream));
		} catch (IOException e) {
			throw new ResourceSetLoaderException(e);
		}
	}

}
